﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.skill.*;

    public class SkillConfig extends Object
    {
        private var _map:Dictionary;
        private var _comboDic:Dictionary;
        private var _serialDic:Dictionary;
        private var _maxLevel:Dictionary;
        private var _serialSkills:Dictionary;
        private var _rune:Dictionary;
        private var _runeCombitDic:Dictionary;
        private static var _instance:SkillConfig;

        public function SkillConfig()
        {
            this._map = new Dictionary();
            this._serialDic = new Dictionary();
            this._serialSkills = new Dictionary();
            this._rune = new Dictionary();
            this._runeCombitDic = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" ResConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function writeForPlayer(param1:Object) : void
        {
            var _loc_2:TSkill = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TSkill();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._map[_loc_2.skillId] = _loc_2;
                if (this._serialDic[_loc_2.series] == null && _loc_2.skillLevel == 1)
                {
                    this._serialDic[_loc_2.series] = _loc_2;
                }
                if (this._serialSkills[_loc_2.series] == null)
                {
                    this._serialSkills[_loc_2.series] = [];
                }
                this._serialSkills[_loc_2.series][_loc_2.skillLevel] = _loc_2;
            }
            return;
        }// end function

        private function writeForBoss(param1:Object) : void
        {
            var _loc_2:TSkill = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TSkill();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._map[_loc_2.skillId] = _loc_2;
            }
            return;
        }// end function

        private function writeForRune(param1:Object) : void
        {
            var _loc_2:TRune = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TRune();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._rune[_loc_2.runeId] = _loc_2;
            }
            return;
        }// end function

        private function writeForRuneCombit(param1:Object) : void
        {
            var _loc_2:TRuneCombination = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TRuneCombination();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._runeCombitDic[_loc_2.id] = _loc_2;
            }
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:Object = null;
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_skill.json");
            this.writeForPlayer(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_skill_boss.json");
            this.writeForBoss(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_rune.json");
            this.writeForRune(_loc_1);
            _loc_1 = ConfigManager.instance.getJSONByFileName("t_rune_combination.json");
            this.writeForRuneCombit(_loc_1);
            return;
        }// end function

        public function getInfoById(param1:int) : TSkill
        {
            return this._map[param1];
        }// end function

        public function getRune(param1:int) : TRune
        {
            return this._rune[param1] as TRune;
        }// end function

        public function getRuneCombit(param1:int) : TRuneCombination
        {
            return this._runeCombitDic[param1];
        }// end function

        public function getFirstComboSkill(param1:int) : TSkill
        {
            var _loc_2:TSkill = null;
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            if (this._comboDic == null)
            {
                this._comboDic = new Dictionary();
                for each (_loc_2 in this._map)
                {
                    
                    if (_loc_2.combo == null || _loc_2.combo.length < 4)
                    {
                        continue;
                    }
                    _loc_3 = _loc_2.combo.split("#");
                    _loc_4 = 0;
                    while (_loc_4 < _loc_3.length)
                    {
                        
                        this._comboDic[parseInt(_loc_3[_loc_4])] = _loc_2;
                        _loc_4++;
                    }
                    this._comboDic[_loc_2.skillId] = _loc_2;
                }
            }
            return this._comboDic[param1] as TSkill;
        }// end function

        public function getRunesBySerial(param1:int, param2:int = -1) : Array
        {
            var _loc_5:TRune = null;
            var _loc_3:Array = [];
            var _loc_4:* = this.getFirstSkillBySerialId(param1);
            for each (_loc_5 in this._rune)
            {
                
                if (SkillUtil.isRuneBelongsToSkill(_loc_5, _loc_4))
                {
                    if (param2 == -1)
                    {
                        _loc_3.push(_loc_5);
                        continue;
                    }
                    if (param2 == _loc_5.level)
                    {
                        _loc_3.push(_loc_5);
                    }
                }
            }
            return _loc_3;
        }// end function

        public function getRuneByItemCode(param1:int) : TRune
        {
            var _loc_2:TRune = null;
            for each (_loc_2 in this._rune)
            {
                
                if (_loc_2.item == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function getNextLevelRune(param1:int) : TRune
        {
            var _loc_3:TRune = null;
            var _loc_2:* = this._rune[param1];
            if (_loc_2 == null)
            {
                return null;
            }
            for each (_loc_3 in this._rune)
            {
                
                if (_loc_3.skillBelong == _loc_2.skillBelong)
                {
                    if (_loc_3.runePos == _loc_2.runePos)
                    {
                        if (_loc_3.level == (_loc_2.level + 1))
                        {
                            return _loc_3;
                        }
                    }
                }
            }
            return null;
        }// end function

        public function getSkillsDic() : Dictionary
        {
            return this._map;
        }// end function

        public function getSkillByLevel(param1:int, param2:int) : TSkill
        {
            var _loc_3:* = this._serialSkills[param1];
            if (_loc_3 == null)
            {
                return null;
            }
            return _loc_3[param2];
        }// end function

        public function getPlayerSkillSerials(param1:int) : Array
        {
            var _loc_3:String = null;
            var _loc_2:Array = [];
            for (_loc_3 in this._serialDic)
            {
                
                if (CareerUtil.isCareerSuit(this._serialDic[_loc_3].career, param1))
                {
                    _loc_2.push(int(_loc_3));
                }
            }
            return _loc_2;
        }// end function

        public function getFirstSkillBySerialId(param1:int) : TSkill
        {
            return this._serialDic[param1] as TSkill;
        }// end function

        public function getSkillByPosAndCareer(param1:int, param2:int) : TSkill
        {
            var _loc_3:TSkill = null;
            for each (_loc_3 in this._serialDic)
            {
                
                if (_loc_3.posType == param1 && _loc_3.career == param2)
                {
                    return _loc_3;
                }
            }
            return null;
        }// end function

        public function getMaxLevelBySerialId(param1:int) : int
        {
            var _loc_4:TSkill = null;
            var _loc_2:* = this._serialSkills[param1];
            if (_loc_2 == null)
            {
                return 1;
            }
            var _loc_3:int = 1;
            for each (_loc_4 in _loc_2)
            {
                
                if (_loc_4.skillLevel > _loc_3)
                {
                    _loc_3 = _loc_4.skillLevel;
                }
            }
            return _loc_3;
        }// end function

        public static function get instance() : SkillConfig
        {
            if (_instance == null)
            {
                _instance = new SkillConfig;
            }
            return _instance;
        }// end function

    }
}
